<?php
/**
 * Verification 组件
 * 验证码
 *
 * @author zzdboy
 * @version 1.0
 */

class VerificationComponent extends Component {
	
	protected $width = 60;
	protected $height = 20;
	protected $color_black = 0;
	protected $color_white = 255;
	protected $color_gray = 229;
	
	/**
	 *
	 * @var $components
	 */
	var $components = array (
			'Session' 
	);
	
	function createImage() {
		
		srand ( ( double ) microtime () * 1000000 );
		$image = imagecreate ( $this->width, $this->height );
		$black = imagecolorallocate ( $image, $this->color_black, $this->color_black, $this->color_black );
		$white = imagecolorallocate ( $image, $this->color_white, $this->color_white, $this->color_white );
		$gray = imagecolorallocate ( $image, $this->color_gray, $this->color_gray, $this->color_gray );
		
		imagefill ( $image, 0, 0, $gray );
		$this->Session->write ( "admin_autonumber", '' );
		
		for($i = 0; $i < 4; $i ++) {
			
			$str = mt_rand ( 1, 5 );
			$size = mt_rand ( 8, 24 );
			$authnumber = mt_rand ( 0, 9 );
			$_SESSION ["admin_autonumber"] .= $authnumber;
			imagestring ( $image, $size, (1 + $i * 16), $str, $authnumber, imagecolorallocate ( $image, rand ( 30, 150 ), rand ( 100, 130 ), rand ( 90, 200 ) ) );
		}
		
		for($i = 0; $i < 233; $i ++) {
			
			$randcolor = imagecolorallocate ( $image, rand ( 33, 99 ), rand ( 19, 155 ), rand ( 19, 222 ) );
			imagesetpixel ( $image, rand () % 100, rand () % 20, $randcolor );
		
		}
		imagepng ( $image );
		imagedestroy ( $image );
	
	}

}
